﻿@using Kunlun.Models;
@using Kunlun.BusinessLogic
@{
	Layout = null;
	var attr = ViewBag.Attribute as Product_attributes;
	var border = ViewBag.Border as Product;
	var paper = ViewBag.Paper as Product;
}
@model Kunlun.Models.Product
<!DOCTYPE html>
<html>
<head>
	<title>@Model.Name</title>
	<link href="@Url.Content("~/Content/themes/base/jquery.ui.all.css")" type="text/css" rel="Stylesheet" />
	<link href="@Url.Content("~/Content/FrameDir/style.css")" type="text/css" rel="Stylesheet" />
	<link href="@Url.Content("~/Content/base/ymPrompt.css")" type="text/css" rel="Stylesheet" />
	<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
	<script src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" type="text/javascript"></script>
	<script src="@Url.Content("~/Content/base/Prompt.js")" type="text/javascript"></script>
	<script type="text/javascript">
		var framewidth = "@attr.Width"; var frameheight = "@attr.Height"
		var photoprice = "@attr.Value1"; var frameprice = 0;
		var glassID = 0, glassPrice = 0,glassName = "";
		var arr = new Array();
		arr[1] = { IsHas: false, Size: 0, Back: "@ViewBag.PaperUrl", BackID: "@paper.pid", name: "@paper.Name", price: @paper.Kacaprice };
		arr[2] = { IsHas: false, Size: 0, Back: "@ViewBag.PaperUrl", BackID: "@paper.pid", name: "@paper.Name", price: @paper.Kacaprice };
		arr[3] = { IsHas: false, Size: 0, Back: "@ViewBag.PaperUrl", BackID: "@paper.pid", name: "@paper.Name", price: @paper.Kacaprice };
		var sel = null;
		var frame_back = "@ViewBag.BorderUrl";
		var frame_ID = "@border.pid";
		var frame_name = "@border.Name";
		var frame_price = "@border.Kacaprice";
		$(function () {
            $( "#dialog-form" ).dialog({
			autoOpen: false,
			show: "blind",
			hide: "explode"
		});
            
			$("#tabs").tabs();
			$("#FrameBar").tabs();
           $(".BarCate dl dd a:first").trigger("click");

			//设置背景色彩
			$(".sel_color li").each(function () {
				$(this).click(function () {
					var strColor = $(this).css("background-color");
					$(".PhotoInfo").css("background-color", strColor);
				});
			});

			$(".pater_list img").each(function () {
				$(this).click(function () {
					if (sel != null) {
						sel.Back = $(this).attr("src");
						sel.BackID = $(this).attr("classID");
						sel.price = $(this).attr("data-price");
						sel.name = $(this).attr("alt");
						ShowFrame();
					} else {
						Alert("请先选择左边卡纸的层数！");
					}
				});
			});

			$(".glass dd input:radio").each(function () {
				$(this).click(function () {
					glassID = $(this).attr("data-id");
					glassPrice = $(this).val();
					glassName = $(this).attr("title");
					ShowFrame();
				});
			});
			ShowFrame();
		});


		function ReturnProduct(str,obj) {
			$(".BarCate dd").each(function () {
				$(this).attr("class", "");
			});
			$(obj).parent().attr("class", "sel");
			$.ajax({
				type: "get",
				dataType: "html",
				url: "/Frame/FrameProduct",
				data: "CategoryID=" + str,
				success: function (msg) {
					var data = msg;
					jQuery("#frame_can").html(data); //加载属性类别
				}

			});
		}
		
		//-----------设置卡纸 层级 默认选择卡纸---------------
		function ChangCurMatLevel(laynum) {
			$(".paper_level ul li").each(function (i) {
				$(this).attr("class", "");
			});
			sel = arr[laynum];
			$("#lay" + laynum).attr("class", "sel");
		}

		function SelectFrame(obj) {
			frame_back = $(obj).attr("pic");
			frame_name = $(obj).attr("alt");
			frame_ID = $(obj).attr("classID");
			frame_price = $(obj).attr("data-price");
			ShowFrame();
		}

		//-------选择卡纸层数 begin--------
		function MatLevelSelect(lay, obj) {
			$(".paper_level ul li").each(function (i) {
				arr[i + 1].IsHas = false;
				$(this).hide();
				$(this).attr("class", "");
			});
			$("#level dd").each(function (i) {
				$(this).attr("class", "");
			});
			$(obj).attr("class", "sel");
			for (var i = 1; i <= lay; i++) {
				arr[i].IsHas = true;
				$("#lay" + i).show();
			}
			sel = null;
			ShowFrame();

            ChangCurMatLevel(1)
		}
		function MatSizeSelect(lay, obj) {
			if (sel == null) {
				return;
			}
			sel.Size = lay;
			$("#size dd").each(function (i) {
				$(this).attr("class", "");
			});
			$(obj).attr("class", "sel");
			ShowFrame();
		}

		function ShowFrame() {
			var paper = "<img id='FrameObj' onload='DrawImage' src='" + $("#FrameObj").attr("src") + "'/>";
			var cs = 0;
			var cprice = frame_price * (@attr.Width + @attr.Height)/50;
			var show = "<li>" + frame_name + "：" + cprice.toFixed(2) + "</li>";
			if(glassID != 0){
				cprice += (glassPrice * framewidth * frameheight / 10000);
				show += "<li>" + glassName + "：" + (glassPrice * framewidth * frameheight / 10000).toFixed(2) + "</li>";
			}
			for (var i = arr.length - 1; i > 0; i--) {
				if (arr[i].IsHas) {
					var sc = (parseInt(arr[i].Size) + 1) * 10;
					cprice += (arr[i].price * framewidth * frameheight)/10000;
					show += "<li>" + arr[i].name + "：" + (arr[i].price * framewidth * frameheight / 10000).toFixed(2) + "</li>";
					cs += sc * 2;
					if (arr[i].BackID == "") {
						paper = "<div  style='padding:" + sc + "px; background-color:#ffffff;'>" + paper + "</div>";
					} else {
						paper = "<div  style='padding:" + sc + "px; background-image:url(" + arr[i].Back + ");'>" + paper + "</div>";
					}
				}
			}
			paper = paper.replace("DrawImage", "DrawImage(this," + (650 - cs) + "," + (450 - cs) + ")");
			cprice += @attr.Value1;
			$("#price span").html("￥"+ cprice.toFixed(2));
			$("#layone").html(paper);
			$("#ResultProduct table tr td").each(function () {
				$(this).css("background-image", "url(" + frame_back + ")");
			});
			$("#ChildShow").html(show);
		}
		//-------选择卡纸层数 end--------

		//等比缩放图片
		function DrawImage(ImgD, kw, kh) {

			var image = new Image();
			image.src = ImgD.src;
			if (image.height / kh < image.width / kw)//说明宽》高＝＝》以宽为标准
			{
				if (image.width > kw) {
					ImgD.width = kw;
					ImgD.height = (image.height * kw) / image.width;

				}
				else {
					ImgD.width = image.width;
					ImgD.height = image.height;
				}
			}
			else//以高为标准
			{
				if (image.height > kh) {
					ImgD.height = kh;
					ImgD.width = (image.width * kh) / image.height;
				}
				else {
					ImgD.width = image.width;
					ImgD.height = image.height;
				}
			}
		}

		function addcart(obj) {
			obj.disabled = "disabled";
			var order = "@Model.pid,@attr.ID,@Convert.ToInt32(FrameType.框画),0,0,1,0";
			order += "|" + frame_ID + ",0,0,@Convert.ToInt32(PaperLevel.外框),0,1,0";
			for (var i = arr.length - 1; i > 0; i--) {
				if (arr[i].IsHas) {
					order += "|" + arr[i].BackID + ",0,0," + i + "," + arr[i].Size + ",1,0";
				}
			}
			if(glassID != 0){
				order += "|" + glassID + ",0,0,0,0,1,0";
			}
			$.post("/MyKunlun/Cart", { "info": order },
			function (data) {
				obj.disabled = "";
				if (data) {
					//Alert("已经放入购物车！");
                    $("#dialog-form").dialog("open");
                    $( "#dialog-form" ).dialog({
			        autoOpen: false,
			        show: "blind",
			        hide: "explode"
		            });
				} else {
					Alert("网络错误！");
				}
			});
		}


		function buy(obj) {
			obj.disabled = "disabled";
			var order = "@Model.pid,@attr.ID,@Convert.ToInt32(FrameType.框画),0,0,1,0";
			order += "|" + frame_ID + ",0,0,0,0,1,0";
			for (var i = arr.length - 1; i > 0; i--) {
				if (arr[i].IsHas) {
					order += "|" + arr[i].BackID + ",0,0," + i + "," + arr[i].Size + ",1,0";
				}
			}
			$.post("/MyKunlun/Cart", { "info": order },
			function (data) {
				if (data) {
					location.href = "/MyKunlun/Cart";
				}
			});
		}

		function ChangeFrame(cid) {
			$(".BarCate dl").each(function () {
				$(this).css("display", "none");
			});
			$("#CCate-" + cid).css("display", "");
			ReturnProduct(cid);
		}

		function scror() {
			var obj = document.getElementById("frame_can");
			var obj_w = parseInt(obj.style.width);
			obj.scrollLeft = (obj.scrollLeft + obj_w);

		}
		function scrol() {
			var obj = document.getElementById("frame_can");
			var obj_w = parseInt(obj.style.width);
			obj.scrollLeft = (obj.scrollLeft - obj_w);
		}
		function AddCollection() {
			$.post("/MyKunlun/InsertCollection", { "pid": "@Model.pid" },
                function (data) {
                	Alert(data);
                });

		}

        function GoonShopping()
        {
        window.location.href='/Store/Frame/Views/'+@Model.pid;
        }
	</script>
</head>
<body>
	<div class="logo">
	</div>
	<div class="PhotoInfo">
		<div id="ResultProduct">
			@{Html.RenderAction("Photo", "Frame", new { productpicUrl = Model.ViewPic });}
		</div>
		<div class="MountInfo">
            @{Html.RenderAction("MountInfo", "Frame", new { attrinfo = attr });}
		</div>
	</div>
	@{Html.RenderAction("ChooseInfo", "Frame", new { CategoryID = 91 });}

    <div id="dialog-form" title="是否继续购物">
	已经放入购物车！<p><a href="javascript:;" onclick="GoonShopping()">继续购物</a> | <a href="javascript:;">关闭当前页</a></p>
    </div>

</body>
</html>
